import { App } from 'vue';
// import useElement from './ElementPlus';

/**
 * 收集公用组件
 * @return {AnyObject}
 */
function collectComponents(): AnyObject {
  const obj: AnyObject = {};

  const components: AnyObject = import.meta.globEager('./*/index.vue');

  for (const path in components) {
    const component = components[path].default;

    obj[component.name] = component;
  }

  return obj;
}

/**
 * 全局注册公用组件
 * @param { APP } app
 */
function install(app: App) {
  // useElement(app); // 按需导入element-plus

  const components = collectComponents();

  for (const i in components) {
    app.component(i, components[i]);
  }
}

export default { install };
